package com.base.home.adapter;

import android.databinding.DataBindingUtil;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import com.alibaba.android.arouter.launcher.ARouter;
import com.base.commonlib.recy.BaseHolderType;
import com.base.commonlib.recy.BasicRecyViewHolder;
import com.base.commonlib.utils.GlideUtil;
import com.base.commonlib.utils.ToastUtil;
import com.base.home.HomeConfig;
import com.base.home.R;
import com.base.home.bean.ConcertSelectEntity;
import com.base.home.databinding.ItemNewBinding;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;

import java.util.ArrayList;
import java.util.List;


/**
 * 精选课程
 *
 * @version V1.0 <描述当前版本功能>
 *          Created by admin on 2018/5/22.
 * @FileName: com.zhongyue.mdchengguan.ui.main.adapter.CategoryViewHolder.java
 * Author weikailiang
 * @date: 2018-05-22 14:22
 */
public class NewViewHolder extends BaseHolderType<ConcertSelectEntity.RecentLearnBean,NewViewHolder.NewsViewHolder> {


    private String parentId;

    public NewViewHolder(String parentId) {
        this.parentId = parentId;
    }

    //    private NewImgAdapter mAdapter;
    @Override
    public int getType(ConcertSelectEntity.RecentLearnBean beans) {
        return HomeConfig.COURSNEW;
    }

    @Override
    public void bindDataToHolder(final NewsViewHolder holder, final ConcertSelectEntity.RecentLearnBean bean, int postion) {
        holder.mBinding.courseTitle.setText(bean.getName());

        holder.mBinding.courseTime.setText(bean.getCreateDate());

//        if (mAdapter == null){
//            mAdapter = new NewImgAdapter(R.layout.item_newimg);
//            holder.mBinding.recycler.setAdapter(mAdapter);
//            GridLayoutManager mLinearment = new GridLayoutManager(holder.mBinding.recycler.getContext(),3);
//            holder.mBinding.recycler.setLayoutManager(mLinearment);
//        }
//        List<String> list = new ArrayList<>();
//        list.add(bean.getCover());
//        list.add(bean.getCover());
//        list.add(bean.getCover());
//        mAdapter.refreshDatas(list);

        GlideUtil.load(holder.mBinding.coursePhoto.getContext(),bean.getCover(),holder.mBinding.coursePhoto);
//        Glide.with(holder.mBinding.coursePhoto.getContext())
//                .load(bean.getCover())
//                .placeholder(R.drawable.ic_empty)
//                .error(R.drawable.ic_empty)
//                .diskCacheStrategy(DiskCacheStrategyG.RESULT)
//                .into(holder.mBinding.coursePhoto);
        holder.mBinding.courseCardview.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                ARouter.getInstance().build("/home/homenew").withString("title",bean.getName())
//                        .withString("detail",bean.getDescription())
//                        .withString("imgurl",bean.getCover())
//                        .withString("id",bean.getId()).navigation();
                if (bean.getType() == 0) {
                    ARouter.getInstance().build("/curriculum/detail")
                            .withString("id", bean.getId())
                            .withString("url", bean.getCover())
                            .navigation();
                }
                if (bean.getType() == 1) {
                    //新闻
                    ARouter.getInstance().build("/home/homenew")
                            .withString("title", bean.getName())
                            //.withString("detail",bean.getDescription())
                            .withString("imgurl",bean.getCover())
                            .withString("id", bean.getId())
                            .withString("type", parentId)
                            .navigation();
                }
            }
        });
    }



    @Override
    public NewsViewHolder buildHolder(ViewGroup parent) {
        return new NewsViewHolder(View.inflate(parent.getContext(), R.layout.item_new, null));
    }



    public static class NewsViewHolder extends BasicRecyViewHolder {
        private ItemNewBinding mBinding;
        public NewsViewHolder(View itemView) {
            this(itemView, null, null);
            mBinding = DataBindingUtil.bind(itemView);
        }
        public NewsViewHolder(View itemView, OnItemClickListener clickListener, OnItemLongClickListener longClickListener) {
            super(itemView, clickListener, longClickListener);
        }
    }
}
